/*   1:    */ package org.jetbrains.jps.model.serialization;
/*   2:    */ 
/*   3:    */

import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.util.JDOMUtil;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.util.text.StringUtil;
import org.jdom.Element;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jps.model.JpsElementChildRole;
import org.jetbrains.jps.model.JpsGlobal;
import org.jetbrains.jps.model.ex.JpsElementChildRoleBase;
import org.jetbrains.jps.model.serialization.impl.JpsPathVariablesConfigurationImpl;
import org.jetbrains.jps.model.serialization.library.JpsLibraryTableSerializer;
import org.jetbrains.jps.model.serialization.library.JpsSdkTableSerializer;

import java.io.File;
import java.io.IOException;
import java.util.Collections;
import java.util.Iterator;
import java.util.Map;

/*   4:    */
/*   5:    */
/*   6:    */
/*   7:    */
/*   8:    */
/*   9:    */
/*  10:    */
/*  11:    */
/*  12:    */
/*  13:    */
/*  14:    */
/*  15:    */
/*  16:    */
/*  17:    */
/*  18:    */
/*  19:    */
/*  20:    */
/*  21:    */
/*  22:    */
/*  23:    */
/*  24:    */
/*  25:    */ 
/*  26:    */ public class JpsGlobalLoader
/*  27:    */   extends JpsLoaderBase
/*  28:    */ {
/*  29: 41 */   private static final Logger b = Logger.getInstance(JpsGlobalLoader.class);
/*  30:    */   public static final String SDK_TABLE_COMPONENT_NAME = "ProjectJdkTable";
/*  31: 43 */   public static final JpsElementChildRole<JpsPathVariablesConfiguration> PATH_VARIABLES_ROLE = JpsElementChildRoleBase.create("path variables");
/*  32: 44 */   private static final JpsGlobalExtensionSerializer[] c = { new GlobalLibrariesSerializer(), new SdkTableSerializer(), new FileTypesSerializer(null) };
/*  33:    */   public static final String FILE_TYPES_COMPONENT_NAME_KEY = "jps.file.types.component.name";
/*  34:    */   private final JpsGlobal d;
/*  35:    */   
/*  36:    */   private JpsGlobalLoader(JpsGlobal paramJpsGlobal, Map<String, String> paramMap)
/*  37:    */   {
/*  38: 51 */     super(new JpsMacroExpander(paramMap));
/*  39: 52 */     this.d = paramJpsGlobal;
/*  40:    */   }
/*  41:    */   
/*  42:    */   public static void loadGlobalSettings(JpsGlobal paramJpsGlobal, String paramString)
/*  43:    */     throws IOException
/*  44:    */   {
/*  45: 56 */     File localFile = new File(FileUtil.toCanonicalPath(paramString));
/*  46: 57 */     new JpsGlobalLoader(paramJpsGlobal, Collections.emptyMap()).a(localFile, new PathVariablesSerializer());
/*  47: 58 */     Map localMap = JpsModelSerializationDataService.computeAllPathVariables(paramJpsGlobal);
/*  48: 59 */     new JpsGlobalLoader(paramJpsGlobal, localMap).a(localFile);
/*  49:    */   }
/*  50:    */   
/*  51:    */   /**
/*  52:    */    * @deprecated
/*  53:    */    */
/*  54:    */   @Nullable
/*  55:    */   public static String getPathVariable(JpsGlobal paramJpsGlobal, String paramString)
/*  56:    */   {
/*  57: 67 */     return JpsModelSerializationDataService.getPathVariableValue(paramJpsGlobal, paramString);
/*  58:    */   }
/*  59:    */   
/*  60:    */   private void a(File paramFile)
/*  61:    */   {
/*  62: 71 */     b.debug("Loading config from " + paramFile.getAbsolutePath());
/*  63:    */     JpsGlobalExtensionSerializer localJpsGlobalExtensionSerializer;
/*  64: 72 */     for (localJpsGlobalExtensionSerializer : c) {
/*  65: 73 */       a(paramFile, localJpsGlobalExtensionSerializer);
/*  66:    */     }
/*  67: 75 */     for (??? = JpsModelSerializerExtension.getExtensions().iterator(); ((Iterator)???).hasNext();)
/*  68:    */     {
/*  69: 75 */       JpsModelSerializerExtension localJpsModelSerializerExtension = (JpsModelSerializerExtension)((Iterator)???).next();
/*  70: 76 */       for (localIterator = localJpsModelSerializerExtension.getGlobalExtensionSerializers().iterator(); localIterator.hasNext();)
/*  71:    */       {
/*  72: 76 */         localJpsGlobalExtensionSerializer = (JpsGlobalExtensionSerializer)localIterator.next();
/*  73: 77 */         a(paramFile, localJpsGlobalExtensionSerializer);
/*  74:    */       }
/*  75:    */     }
/*  76:    */     Iterator localIterator;
/*  77:    */   }
/*  78:    */   
/*  79:    */   private void a(File paramFile, JpsGlobalExtensionSerializer paramJpsGlobalExtensionSerializer)
/*  80:    */   {
/*  81: 83 */     loadComponents(paramFile, "other.xml", paramJpsGlobalExtensionSerializer, this.d);
/*  82:    */   }
/*  83:    */   
/*  84:    */   public static class PathVariablesSerializer
/*  85:    */     extends JpsGlobalExtensionSerializer
/*  86:    */   {
/*  87:    */     public static final String MACRO_TAG = "macro";
/*  88:    */     public static final String NAME_ATTRIBUTE = "name";
/*  89:    */     public static final String VALUE_ATTRIBUTE = "value";
/*  90:    */     
/*  91:    */     public PathVariablesSerializer()
/*  92:    */     {
/*  93: 92 */       super("PathMacrosImpl");
/*  94:    */     }
/*  95:    */     
/*  96:    */     public void loadExtension(@NotNull JpsGlobal paramJpsGlobal, @NotNull Element paramElement)
/*  97:    */     {
/*  98: 97 */       if (paramJpsGlobal == null) {
/*  99: 97 */         throw new IllegalArgumentException(String.format("Argument %s for @NotNull parameter of %s.%s must not be null", new Object[] { "0", "org/jetbrains/jps/model/serialization/JpsGlobalLoader$PathVariablesSerializer", "loadExtension" }));
/* 100:    */       }
/* 101: 97 */       if (paramElement == null) {
/* 102: 97 */         throw new IllegalArgumentException(String.format("Argument %s for @NotNull parameter of %s.%s must not be null", new Object[] { "1", "org/jetbrains/jps/model/serialization/JpsGlobalLoader$PathVariablesSerializer", "loadExtension" }));
/* 103:    */       }
/* 104: 97 */       JpsPathVariablesConfiguration localJpsPathVariablesConfiguration = (JpsPathVariablesConfiguration)paramJpsGlobal.getContainer().setChild(JpsGlobalLoader.PATH_VARIABLES_ROLE, new JpsPathVariablesConfigurationImpl());
/* 105: 98 */       for (Element localElement : JDOMUtil.getChildren(paramElement, "macro"))
/* 106:    */       {
/* 107: 99 */         String str1 = localElement.getAttributeValue("name");
/* 108:100 */         String str2 = localElement.getAttributeValue("value");
/* 109:101 */         if ((str1 != null) && (str2 != null)) {
/* 110:102 */           localJpsPathVariablesConfiguration.addPathVariable(str1, StringUtil.trimEnd(FileUtil.toSystemIndependentName(str2), "/"));
/* 111:    */         }
/* 112:    */       }
/* 113:    */     }
/* 114:    */     
/* 115:    */     public void saveExtension(@NotNull JpsGlobal paramJpsGlobal, @NotNull Element paramElement)
/* 116:    */     {
/* 117:109 */       if (paramJpsGlobal == null) {
/* 118:109 */         throw new IllegalArgumentException(String.format("Argument %s for @NotNull parameter of %s.%s must not be null", new Object[] { "0", "org/jetbrains/jps/model/serialization/JpsGlobalLoader$PathVariablesSerializer", "saveExtension" }));
/* 119:    */       }
/* 120:109 */       if (paramElement == null) {
/* 121:109 */         throw new IllegalArgumentException(String.format("Argument %s for @NotNull parameter of %s.%s must not be null", new Object[] { "1", "org/jetbrains/jps/model/serialization/JpsGlobalLoader$PathVariablesSerializer", "saveExtension" }));
/* 122:    */       }
/* 123:109 */       JpsPathVariablesConfiguration localJpsPathVariablesConfiguration = JpsModelSerializationDataService.getPathVariablesConfiguration(paramJpsGlobal);
/* 124:110 */       if (localJpsPathVariablesConfiguration != null) {
/* 125:111 */         for (Map.Entry localEntry : localJpsPathVariablesConfiguration.getAllUserVariables().entrySet())
/* 126:    */         {
/* 127:112 */           Element localElement = new Element("macro");
/* 128:113 */           localElement.setAttribute("name", (String)localEntry.getKey());
/* 129:114 */           localElement.setAttribute("value", (String)localEntry.getValue());
/* 130:115 */           paramElement.addContent(localElement);
/* 131:    */         }
/* 132:    */       }
/* 133:    */     }
/* 134:    */   }
/* 135:    */   
/* 136:    */   public static class GlobalLibrariesSerializer
/* 137:    */     extends JpsGlobalExtensionSerializer
/* 138:    */   {
/* 139:    */     public GlobalLibrariesSerializer()
/* 140:    */     {
/* 141:123 */       super("libraryTable");
/* 142:    */     }
/* 143:    */     
/* 144:    */     public void loadExtension(@NotNull JpsGlobal paramJpsGlobal, @NotNull Element paramElement)
/* 145:    */     {
/* 146:128 */       if (paramJpsGlobal == null) {
/* 147:128 */         throw new IllegalArgumentException(String.format("Argument %s for @NotNull parameter of %s.%s must not be null", new Object[] { "0", "org/jetbrains/jps/model/serialization/JpsGlobalLoader$GlobalLibrariesSerializer", "loadExtension" }));
/* 148:    */       }
/* 149:128 */       if (paramElement == null) {
/* 150:128 */         throw new IllegalArgumentException(String.format("Argument %s for @NotNull parameter of %s.%s must not be null", new Object[] { "1", "org/jetbrains/jps/model/serialization/JpsGlobalLoader$GlobalLibrariesSerializer", "loadExtension" }));
/* 151:    */       }
/* 152:128 */       JpsLibraryTableSerializer.loadLibraries(paramElement, paramJpsGlobal.getLibraryCollection());
/* 153:    */     }
/* 154:    */     
/* 155:    */     public void saveExtension(@NotNull JpsGlobal paramJpsGlobal, @NotNull Element paramElement)
/* 156:    */     {
/* 157:133 */       if (paramJpsGlobal == null) {
/* 158:133 */         throw new IllegalArgumentException(String.format("Argument %s for @NotNull parameter of %s.%s must not be null", new Object[] { "0", "org/jetbrains/jps/model/serialization/JpsGlobalLoader$GlobalLibrariesSerializer", "saveExtension" }));
/* 159:    */       }
/* 160:133 */       if (paramElement == null) {
/* 161:133 */         throw new IllegalArgumentException(String.format("Argument %s for @NotNull parameter of %s.%s must not be null", new Object[] { "1", "org/jetbrains/jps/model/serialization/JpsGlobalLoader$GlobalLibrariesSerializer", "saveExtension" }));
/* 162:    */       }
/* 163:133 */       JpsLibraryTableSerializer.saveLibraries(paramJpsGlobal.getLibraryCollection(), paramElement);
/* 164:    */     }
/* 165:    */   }
/* 166:    */   
/* 167:    */   public static class SdkTableSerializer
/* 168:    */     extends JpsGlobalExtensionSerializer
/* 169:    */   {
/* 170:    */     public SdkTableSerializer()
/* 171:    */     {
/* 172:139 */       super("ProjectJdkTable");
/* 173:    */     }
/* 174:    */     
/* 175:    */     public void loadExtension(@NotNull JpsGlobal paramJpsGlobal, @NotNull Element paramElement)
/* 176:    */     {
/* 177:144 */       if (paramJpsGlobal == null) {
/* 178:144 */         throw new IllegalArgumentException(String.format("Argument %s for @NotNull parameter of %s.%s must not be null", new Object[] { "0", "org/jetbrains/jps/model/serialization/JpsGlobalLoader$SdkTableSerializer", "loadExtension" }));
/* 179:    */       }
/* 180:144 */       if (paramElement == null) {
/* 181:144 */         throw new IllegalArgumentException(String.format("Argument %s for @NotNull parameter of %s.%s must not be null", new Object[] { "1", "org/jetbrains/jps/model/serialization/JpsGlobalLoader$SdkTableSerializer", "loadExtension" }));
/* 182:    */       }
/* 183:144 */       JpsSdkTableSerializer.loadSdks(paramElement, paramJpsGlobal.getLibraryCollection());
/* 184:    */     }
/* 185:    */     
/* 186:    */     public void saveExtension(@NotNull JpsGlobal paramJpsGlobal, @NotNull Element paramElement)
/* 187:    */     {
/* 188:149 */       if (paramJpsGlobal == null) {
/* 189:149 */         throw new IllegalArgumentException(String.format("Argument %s for @NotNull parameter of %s.%s must not be null", new Object[] { "0", "org/jetbrains/jps/model/serialization/JpsGlobalLoader$SdkTableSerializer", "saveExtension" }));
/* 190:    */       }
/* 191:149 */       if (paramElement == null) {
/* 192:149 */         throw new IllegalArgumentException(String.format("Argument %s for @NotNull parameter of %s.%s must not be null", new Object[] { "1", "org/jetbrains/jps/model/serialization/JpsGlobalLoader$SdkTableSerializer", "saveExtension" }));
/* 193:    */       }
/* 194:149 */       JpsSdkTableSerializer.saveSdks(paramJpsGlobal.getLibraryCollection(), paramElement);
/* 195:    */     }
/* 196:    */   }
/* 197:    */   
/* 198:    */   private static class FileTypesSerializer
/* 199:    */     extends JpsGlobalExtensionSerializer
/* 200:    */   {
/* 201:    */     FileTypesSerializer(JpsGlobalLoader.0 param0)
/* 202:    */     {
/* 203:153 */       this();
/* 204:    */     }
/* 205:    */     
/* 206:    */     private FileTypesSerializer()
/* 207:    */     {
/* 208:155 */       super(System.getProperty("jps.file.types.component.name", "FileTypeManager"));
/* 209:    */     }
/* 210:    */     
/* 211:    */     public void loadExtension(@NotNull JpsGlobal paramJpsGlobal, @NotNull Element paramElement)
/* 212:    */     {
/* 213:160 */       if (paramJpsGlobal == null) {
/* 214:160 */         throw new IllegalArgumentException(String.format("Argument %s for @NotNull parameter of %s.%s must not be null", new Object[] { "0", "org/jetbrains/jps/model/serialization/JpsGlobalLoader$FileTypesSerializer", "loadExtension" }));
/* 215:    */       }
/* 216:160 */       if (paramElement == null) {
/* 217:160 */         throw new IllegalArgumentException(String.format("Argument %s for @NotNull parameter of %s.%s must not be null", new Object[] { "1", "org/jetbrains/jps/model/serialization/JpsGlobalLoader$FileTypesSerializer", "loadExtension" }));
/* 218:    */       }
/* 219:160 */       Element localElement = paramElement.getChild("ignoreFiles");
/* 220:161 */       if (localElement != null) {
/* 221:162 */         paramJpsGlobal.getFileTypesConfiguration().setIgnoredPatternString(localElement.getAttributeValue("list"));
/* 222:    */       }
/* 223:    */     }
/* 224:    */     
/* 225:    */     public void saveExtension(@NotNull JpsGlobal paramJpsGlobal, @NotNull Element paramElement)
/* 226:    */     {
/* 227:168 */       if (paramJpsGlobal == null) {
/* 228:168 */         throw new IllegalArgumentException(String.format("Argument %s for @NotNull parameter of %s.%s must not be null", new Object[] { "0", "org/jetbrains/jps/model/serialization/JpsGlobalLoader$FileTypesSerializer", "saveExtension" }));
/* 229:    */       }
/* 230:168 */       if (paramElement == null) {
/* 231:168 */         throw new IllegalArgumentException(String.format("Argument %s for @NotNull parameter of %s.%s must not be null", new Object[] { "1", "org/jetbrains/jps/model/serialization/JpsGlobalLoader$FileTypesSerializer", "saveExtension" }));
/* 232:    */       }
/* 233:    */     }
/* 234:    */   }
/* 235:    */ }



/* Location:           E:\idea\

 * Qualified Name:     org.jetbrains.jps.model.serialization.JpsGlobalLoader

 * JD-Core Version:    0.7.0.1

 */